Skip to content

fix(policy): hold approve and merge on unlifted STOPP signals - #18

Merged
ellmos-multi-bot merged 3 commits into
mainfrom
fix/stop-signal-merge-gate
Nov 22, 2026
Merged

ellmos-multi-bot merged 3 commits into
mainfrom
fix/stop-signal-merge-gate

Conversation

@lukisch

@lukisch lukisch commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Twice, a pull request was approved and merged minutes after a reviewing instance had posted a STOPP / "NICHT MERGEN" signal. Both times the signal stood under a different account than the merging bot (2026-09-22 and 2026-11-22, the latter merged six minutes after the STOPP comment). Nothing in the typed actions read PR comments or reviews before approving or merging.

Change

  • New stop_gate module with one pure evaluate() and a fetching hold_reason(). It reads all issue comments and reviews of the PR fresh, orders them by time and holds when an unlifted stop exists:
    • Stop: STOPP, STOP (capitals), nicht mergen, do not merge, don't merge, REQUEST_CHANGES in a comment or review body, or a CHANGES_REQUESTED review. Negations ("kein STOPP") do not count. Dismissed reviews are ignored.
    • Lift (tightened after the review STOPP, commit 55b7697): a later line that is the formula alone (STOPP aufgehoben, STOP lifted, Merge freigegeben, cleared to merge) by the same account or by an account in the new multi_bot.policy.stop_release_accounts (default []); questions, negations and extra words on that line never count. Or a later APPROVED review by the same account on a head that GitHub compare proves newer than every head the stop named; a stop without a head is lifted only by the formula; the configured merge account never lifts by approving.
    • Fail closed: unreadable comment or review lists, or entries without timestamps, are a HOLD.
  • Inline review comments are read as stop sources. A held action reports armed auto-merge.
  • pr.merge and pr.review with APPROVE both call this one gate before writing, so every core merge path passes it. Merges in the instance go through core act pr.merge.
  • The packaged MULTI-BOT prompt documents the gate and the new switch. There is also a CHANGELOG entry.

Tests

  • tests/test_stop_gate.py:
    • STOPP comment under a foreign account holds both approve and merge.
    • A NICHT-MERGEN review holds the merge even after a bot approve.
    • A later release comment lifts the stop.
    • Release rules: a foreign account cannot lift, an owner account can, ordering is respected, an approve on a new head lifts, an approve on the same head does not.
    • Negative control: no stop signal, so the merge and the approve go through.
    • Fail closed on unreadable data.
  • Existing fixtures got the comment and review list endpoints, plus real review fields (state, submitted_at).
  • Local runs:
    • Targeted: 134 passed (stop_gate, typed_actions, pr_review_action, multibot_resources).
    • Full suite before the final prompt fix: 493 passed, 2 skipped. The one failure was the prompt-documents-every-switch test, which this PR fixes.
    • ruff check and ruff format --check are clean.

Not included

  • pr.ready is not gated. Readying a draft is not a merge, and the merge stays gated.

Ticket: T-20261122-473151443

🤖 Generated with Claude Code

https://claude.ai/code/session_01THB2EyNYw5th8eXvfU8evh

A STOPP / "NICHT MERGEN" / "do not merge" / REQUEST_CHANGES text in a PR
comment or review, or a CHANGES_REQUESTED review, now holds pr.merge and
pr.review APPROVE regardless of the posting account. Only a later explicit
release by the same account (or a policy.stop_release_accounts entry), or a
later approve by the same account on another head, lifts it. Unreadable
comments or reviews fail closed.

Both typed actions route through one gate (stop_gate.hold_reason), so every
core merge path passes it. Regression fixtures mirror the merge six minutes
after a STOPP comment (2026-11-22) and the 2026-09-22 NICHT-MERGEN case.

Ticket: T-20261122-473151443

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01THB2EyNYw5th8eXvfU8evh
@lukisch
lukisch marked this pull request as draft November 22, 2026 21:41
@lukisch

lukisch commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Independent review, head e595b27: STOPP, not merged

Verdict: STOPP. The gate is wired correctly into both core write paths, and it fails closed on unreadable data. The release side, however, lifts stops on texts that are not releases. That is a fail-open path inside a gate that is meant to fail closed. This PR stays a draft. The fixes are small; details below.

What holds (measured on macOS, Python 3.12, fresh clone, throwaway venv)

  • ruff clean. Full suite 489 passed, 7 skipped, in 2 of 2 runs. Only platform skips differ from the author's Windows numbers.
  • With src reset to main, the gate tests go red: 3 failed.
  • Negative controls, all red as expected:
    • Merge gate removed in exec_merge: 3 failed.
    • Approve gate removed: 1 failed.
    • Comment-list read error treated as empty: 1 failed.
    • Unreadable comment skipped instead of HOLD: 1 failed.
    • Any account may release all stops: 1 failed.
    • Approve on the stopped head lifts: 1 failed.
  • Merge paths in the core: the only merge write is PUT …/pulls/{n}/merge in exec_merge, and it is gated. The only approve write is pr.review with APPROVE, and it is gated too. api.request raw writes are limited to POST issues/{n}/comments|labels, so neither a raw merge nor a raw review bypasses the gate. The core has no auto-merge mutation. GraphQL is used only for markPullRequestReadyForReview and the merge readback.
  • Fail-closed probes held:
    • deleted user (user: null)
    • review without submitted_at
    • body: null
    • foreign STOPP aufgehoben
    • foreign approve on a new head
    • an owner release followed by a new stop
    • CHANGES_REQUESTED followed by a same-account approve on the same head
  • Pagination: get_paginated follows rel="next" and refuses partial results, so a stop on page 2 is still seen.

Blocking: false releases (probe stop_gate.evaluate, 7 of 22 cases wrong)

Each case is a stop comment that names the head, followed by a later comment by the same account. Every one of these came back PASS, meaning the stop was lifted, although none of them is a release:

Later comment Why it matches _RELEASE
weiterhin nicht fuer den Merge freigegeben, Tests rot. lookbehind only checks the word directly before
Das ist nicht mehr freigegeben. same
noch nicht freigegeben (two spaces) lookbehind is fixed to a single \s
not yet freigegeben same
freigegeben wird erst nach Retest bare word anywhere
Ist der STOPP aufgehoben? a question counts as a release

There is a seventh case. A stop comment without a SHA, followed by a same-account APPROVED on the same head, also lifts the stop. With no named prefix, any(...) over an empty set is False, so every later approve counts as "another head". The PR description says the release must come on a new head.

Why this matters here: during a bot-account fallback, the private instance wrapper acts as the owner account. That is the same account that posts the independent STOPP comments. "Same account" therefore does not mean "same instance". A routine bot comment that happens to contain "freigegeben" in any grammatical form would lift a human stop.

Suggested fix, kept small:

  1. Accept a release only as an explicit, unnegated line. For example ^\s*(?:STOPP?\s+(?:ist\s+)?aufgehoben|freigegeben|stop\s+lifted|cleared\s+to\s+merge)\b[^?\n]*$, matched per line with re.M. Reject the line if it contains nicht|kein|not|no|noch|erst|wird before the keyword.
  2. When a comment stop names no SHA, store the head that was current when the gate read the stop. If that is not known, require an explicit release and do not accept a later approve.
  3. Do not count the authenticated merge account as a releaser by comment. That account is the one writing.
  4. Add these probe rows as tests. The probe script is reproducible from the case table above.

Not part of this PR, but asked for: gh-CLI paths outside the core (private instance, reported separately)

  • The base instance prompt still prescribes gh pr merge … --match-head-commit. Only the full profile switches to pr.merge.
  • The private instance wrapper passes gh pr merge, gh pr review --approve and gh api -X PUT …/merge through. It refuses only auth, config, extension and alias. These paths skip stop_gate entirely. They need either a wrapper refusal or a prompt change. That cannot be fixed in this repository.
  • --auto is forbidden only by prompt text. If auto-merge was enabled on a PR earlier by someone else, GitHub merges without any gate. A pre-merge check of autoMergeRequest is worth adding to pr.merge, so that a HOLD also covers PRs where auto-merge is already armed.
  • STOPP text in inline review comments (pulls/{n}/comments) is not read. A line comment saying "NICHT MERGEN" inside a COMMENTED review with an empty body is missed.

No branch changes from my side; findings only.

Addresses the independent review STOPP on this PR (7 of 22 probes lifted a
stop wrongly):

- Release only by a line that is the formula alone (STOPP aufgehoben, STOP
  lifted, Merge freigegeben, cleared to merge). Questions, negations and
  extra words on that line never count; a release line next to a stop line
  in the same comment keeps the stop.
- Approve of the stopping account lifts only on a head that GitHub compare
  proves newer than every head the stop named. A stop without a head is
  lifted only by the release line.
- The configured merge account never lifts a stop by approving.
- Inline review comments (pulls/{n}/comments) are read as stop sources.
- A held merge or approve reports armed auto-merge (auto_merge) so that it
  can be disabled.
- All review probes are now parametrized tests.

Ticket: T-20261122-473151443

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01THB2EyNYw5th8eXvfU8evh
@lukisch

lukisch commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Independent re-review, head 55b7697: STOPP (one small residual), not merged

All round-1 findings are fixed and pinned by tests. One residual fail-open path is left in the release parser. It is small but realistic, so this PR stays a draft. The fix is about two lines.

Measured (macOS, Python 3.12, fresh clone, throwaway venv)

  • ruff clean.

  • Full suite: 516 passed, 7 skipped, in 2 of 2 runs.

  • With src reset to main, the gate tests fail: 8 failed.

  • Bypass probes: 33 of 36 behave as specified. All 22 round-1 rows now hold or pass as expected, including:

    • every negation variant
    • the question form
    • a stop without a SHA followed by an approve on the same head or on a newer head
    • an approve on a diverged head
    • a foreign approve
  • Further rows behave as expected: the merge account approving, an inline NICHT MERGEN with original_commit_id, a release line next to a NICHT MERGEN line, a release posted before the stop, an owner release, a non-dict item, and date-like hex tokens.

  • Negative controls: 11 of 12 mutations turn tests red.

    Mutation Failed tests
    Merge gate removed 7
    Approve gate removed 1
    List read error treated as fail-open 3
    Unreadable comment skipped 1
    Any account releases all 1
    Approve lifts without compare proof 3
    Merge account may lift by approve 1
    search instead of fullmatch 1
    Inline comments ignored 1
    Auto-merge note removed 1
    No-SHA stop lifted by approve 4

    The 12th mutation, replacing the early non-dict check with pass, stays green. No test feeds a non-dict item.

Blocking residual: quoted or fenced formula lines count as a release

_lines() strips > and backticks before fullmatch. As a result, a quote-reply or a code block from the stopping account lifts its own stop:

Later comment by the stopping account Result
> Merge freigegeben followed by Nein, noch nicht. lifted (expected HOLD)
> STOPP aufgehoben (quote only) lifted (expected HOLD)
a fenced code block whose only line is STOPP aufgehoben lifted (expected HOLD)

GitHub's "Quote reply" produces exactly the first form. A reviewer who quotes the author's release line in order to contradict it would release their own stop.

Suggested fix:

  • Do not strip > or backticks. Skip blockquote lines (lstrip().startswith(">")) and lines inside fenced blocks before the fullmatch.
  • Add the three rows above as probe tests.
  • Add one test with a non-dict item, so the early check is pinned.

Notes, not blocking

  • Hex-like tokens of 7 or more characters in a stop comment, such as long issue or comment numbers or 20261122, become "named heads". Compare on them fails, so such a stop can then be lifted only by the formula. This fails closed, which is acceptable.
  • The auto-merge note appears only when a hold exists. That is fine, because the gate cannot stop GitHub's own auto-merge in any case.

No branch changes from my side; findings only.

Round-2 review residual: _lines() stripped ">" and backticks before the
fullmatch, so a quote-reply ("> Merge freigegeben" + "Nein, noch nicht."),
a quote alone or a fenced block containing only the formula lifted the
quoting account's own stop. ">" and backticks are no longer stripped and
lines inside ``` / ~~~ fences are skipped for releases; stop detection
still reads every line (fail closed).

Tests pin the three review rows, a tilde fence, a release after a closed
fence and the early non-dict check. Mutations "strip > and backticks",
"no fence tracking" and "drop non-dict check" each turn tests red.

Ticket: T-20261122-473151443

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01THB2EyNYw5th8eXvfU8evh
@lukisch

lukisch commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Independent re-review, head af076ed: approved for merge

STOPP aufgehoben

Measured on macOS (Python 3.12, fresh clone, throwaway venv):

  • ruff clean. Full suite: 522 passed, 7 skipped, in 2 of 2 runs. With src reset to main, the gate tests go red (8 failed).

  • Bypass probes: 45 of 46 behave as specified. They include all rows from rounds 1 and 2, plus:

    • ~~~ fences and fences with an info string
    • an unclosed fence, and a shorter closing fence that leaves the fence open
    • a release line after a properly closed fence
    • a quoted fence and nested quotes
    • a STOPP inside a fence, which still stops
    • a heading release
  • Negative controls: 14 of 14 mutations go red.

    Mutation Failed tests
    Merge gate removed 7
    Approve gate removed 1
    List read error treated as fail-open 3
    Unreadable comment skipped 1
    Any account releases all 1
    Approve lifts without compare proof 3
    Merge account may lift by approve 1
    search instead of fullmatch 4
    Inline comments ignored 1
    Auto-merge note removed 1
    No-SHA stop lifted by approve 4
    Non-dict check removed 1
    Fences not detected 2
    > and backticks stripped again 2
  • Privacy scan of the diff: 0 hits.

Residual, not blocking: an indented code block (four leading spaces) whose only line is the formula still counts as a release. A reviewer's own comment would hardly contain that, so I leave it as a possible follow-up. Treating lines with 4 or more leading spaces after a blank line as code would close it.

@lukisch
lukisch marked this pull request as ready for review November 22, 2026 22:35
@ellmos-multi-bot
ellmos-multi-bot merged commit e270808 into main Nov 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants